package nl.haemers.data.reflection 
{
	import flash.utils.Dictionary;
	import nl.haemers.data.collections.List;
	import nl.haemers.data.constants.ReflectionConstants;
	import nl.haemers.data.reflection.IParameter;
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class Parameters implements IParameters 
	{
		private var _list					:List;
		
		public function Parameters(description:XML, names:Array = null) 
		{
			_list = new List();
			init(description, names);
		}
		
		/** Public methods **/
		public function getParameter(name:String) : IParameter 
		{
			return _list.search(name) as IParameter;
		}
		
		public function hasParameter(name:String) : Boolean
		{
			return _list.hasKey(name);
		}
		
		public function getParameters() : Dictionary
		{
			return _list.items;
		}
		
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		private function init(xml:XML, names:Array = null) : void
		{
			var max:int;
			var index:int = 0;
			if (names)
			{
				max = names.length;
			}
			
			for each(var node:XML in xml.elements(ReflectionConstants.XML_PARAMETER))
			{
				if (max > index)
				{
					var name:String = names[index];
				}
				var parameter:Parameter = new Parameter(node, name);
				
				_list.add(parameter.toString(), parameter);
				index++;
			}
		}
		
	/*	
		<parameter index="1" type="String" optional="false"/>
    <parameter index="2" type="String" optional="false"/>
    <parameter index="3" type="int" optional="false"/>
    <parameter index="4" type="Object" optional="true"/>
    */
	}

}